package com.nce.entity;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import com.nce.entity.account.User;


/**
 *新闻 ,论坛,博客,微博基类
 * @author GT
 */
@MappedSuperclass
public class BaseNews extends IdEntity implements Comparable {

	private static final long serialVersionUID = 7589108853815428562L;
	
	/*
	  CREATE TABLE `news` (
	  `id` int(11) NOT NULL auto_increment,
	  `title` varchar(255) default NULL,#标题
	  `content` mediumtext,#内容
	  `url` varchar(255) default NULL,#链接	  
	  `forum_name` varchar(255) default NULL,#网站名
	  `uid` mediumint(9) default NULL,#文章所属的用户
	  `tm_spider` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
	   `Is_New ` varchar(255) default NULL,#新文章标志
	  `Has_Export` varchar(255) default NULL,#导出标志  
	  
	  `tm_last_rply` datetime default NULL,
	  `tm_post` datetime default NULL,#发文时间
	  PRIMARY KEY  (`id`)
	) ENGINE=InnoDB DEFAULT CHARSET=utf8;

	 */

	private String title;
	private String content;
	private String url;	
	private String forumName;
	private User user;
	private Date tmSpider;
	private Date tmPost;

	private String isNew = "true";
	private String hasExport;
	
	private String viewContent;
	private String viewTitle;
	
	
	
	

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Date getTmPost() {
		return tmPost;
	}




	public void setTmPost(Date tmPost) {
		this.tmPost = tmPost;
	}
	

	public String getForumName() {
		return forumName;
	}

	public void setForumName(String forumName) {
		this.forumName = forumName;
	}

	@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name = "uid")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Date getTmSpider() {
		return tmSpider;
	}

	public void setTmSpider(Date tmSpider) {
		this.tmSpider = tmSpider;
	}

	@Transient 
	public String getIsNew() {
		return isNew;
	}

	public void setIsNew(String isNew) {
		this.isNew = isNew;
	}
	@Transient 
	public String getHasExport() {
		return hasExport;
	}

	public void setHasExport(String hasExport) {
		this.hasExport = hasExport;
	}

	public String formatBaseNewsForExport(){
//		String result = "标题,链接,发文媒体,发文时间,内容摘要\r\n";
		StringBuilder sb = new StringBuilder();
		sb.append("\"").append(getTitle()).append("\",");
		sb.append("\"").append(getUrl()).append("\",");
		sb.append("\"").append(getForumName()).append("\",");
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		sb.append("\"").append(df.format(getTmPost())).append("\",");
		sb.append("\"").append(getContent()).append("\",");
		sb.append("\r\n");
		return sb.toString();
	}
	

	@Transient 
	public String getViewContent() {
		return viewContent;
	}

	public void setViewContent(String viewContent) {
		this.viewContent = viewContent;
	}

	@Transient 
	public String getViewTitle() {
		return viewTitle;
	}

	public void setViewTitle(String viewTitle) {
		this.viewTitle = viewTitle;
	}

	@Override
	public int compareTo(Object o) {
		BaseNews ob = (BaseNews)o;
		return ob.getTmPost().compareTo(this.tmPost);
	}

}
